package com.liuqi.openai.data.message;

import com.liuqi.openai.tool.ToolCallRequest;
import java.util.List;

import static com.liuqi.openai.data.message.ChatMessageType.ASSISTANT;

/**
 * AI响应消息
 *
 * 消息可以包含文本响应以及思考内容或执行工具的请求
 *
 * 在工具执行的情况下，对此消息的响应应该是{@link #toolCallRequests}
 *
 * @author liuqi
 * @date 2025/7/19
 **/
public class AiMessage extends ChatMessage {

    /**
     * response id
     */
    private final String id;

    /**
     * 思考内容
     *
     * 如果有思考内容, 则不为空
     */
    private final String reasoningContent;

    /**
     * 工具调用
     *
     * 如果有工具调用, 则不为空
     */
    private final List<ToolCallRequest> toolCallRequests;

    AiMessage(String id,
              String content,
              String reasoningContent,
              List<ToolCallRequest> toolCallRequests) {
        super(content, ASSISTANT);
        this.id = id;
        this.reasoningContent = reasoningContent;
        this.toolCallRequests = toolCallRequests;
    }

    public String id() {
        return this.id;
    }

    public String reasoningContent() {
        return this.reasoningContent;
    }

    public List<ToolCallRequest> toolCallRequests() {
        return this.toolCallRequests;
    }

    public static AiMessage from(String id, String text) {
        return new AiMessage(id, text, null, null);
    }

    public static AiMessage from(String id, String text, String reasoningContent) {
        return new AiMessage(id, text, reasoningContent, null);
    }

    public static AiMessage from(String id, String reasoningContent, List<ToolCallRequest> toolCallRequests) {
        return new AiMessage(id,null, reasoningContent, toolCallRequests);
    }

    public static AiMessage from(String id, List<ToolCallRequest> toolCallRequests) {
        return new AiMessage(id, null, null, toolCallRequests);
    }

    public static AiMessage aiMessage(String id,
                                      String content,
                                      String reasoningContent,
                                      List<ToolCallRequest> toolCallRequests) {
        return new AiMessage(id, content, reasoningContent, toolCallRequests);
    }

    @Override
    public String toString() {
        return "AiMessage{" +
                "reasoningContent='" + reasoningContent + '\'' +
                ", toolCallRequests=" + toolCallRequests +
                ", content='" + text + '\'' +
                ", type=" + type +
                '}';
    }
}
